package com.dycx.system.converter;

import java.time.LocalDateTime;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

import java.io.Serializable;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.system.entity.NotifyDO;
import com.dycx.system.vo.NotifyVO;
import com.dycx.system.dto.NotifyDTO;

/**
 * (Notify)实体转换类
 *
 * @author wuzongbin
 * @since 2023-12-04 22:59:01
 */


@Data
public class NotifyConverter implements Serializable {
    public static NotifyDO dtoToEntity(NotifyDTO dto) {
        if (dto == null) return null;
        NotifyDO entity = BeanUtil.toBean(dto, NotifyDO.class);
        return entity;
    }

    public static NotifyVO entityToVo(NotifyDO entity) {
        if (entity == null) return null;
        NotifyVO vo = BeanUtil.toBean(entity, NotifyVO.class);

        return vo;
    }

    public static List<NotifyVO> entityToVoList(List<NotifyDO> entityList) {
        List<NotifyVO> voList = new ArrayList<>();
        for (NotifyDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<NotifyVO> entityToVoPage(Page<NotifyDO> page) {

        List<NotifyVO> newRecords = new ArrayList<>();

        List<NotifyDO> records = page.getRecords();
        for (NotifyDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<NotifyVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
